package kaoshi;

public class Quest4 {
    public static void main(String[] args) {
        int n = 5;
        int nums[]={1,2,3,4,5};
        int a[]=new int[nums.length];
        find(n,nums,0,a,0);
    }

    public static void find(int n, int nums[],int sum,int a[],int index) {
        if (sum==n){
            for (int i = 0 ;i<index;i++) {
                if (a[i]==1)
                    System.out.print(nums[i]+" ");
            }
            System.out.println();
            return;
        }
        if (index>nums.length-1)
            return;
        if (sum>n)
            return;
        a[index]=1;
        find(n,nums,sum+nums[index],a,index+1);
        a[index]=0;
        find(n,nums,sum,a,index+1);
    }
}
